import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import '../../provide/details_info.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DetailTopArea extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Provide<DetailsInfoProvide>(
      builder: (context,child,val){
        var goodsInfo = Provide.value<DetailsInfoProvide>(context).goodsInfo.data.goodInfo;
        if(goodsInfo != null){
          return Container(
            color: Colors.white,
            padding: EdgeInsets.only(bottom: 8.0),
            child: Column(
              children: <Widget>[
                _goodsImage(goodsInfo.image1),
                _goodsName(goodsInfo.goodsName),
                _gooddsNum(goodsInfo.goodsSerialNumber),
                _goodsPrice(goodsInfo.presentPrice,goodsInfo.oriPrice)
              ],
            ),
          );
        } else {
          return Text('正在加载中......');
        }
      },
    );
  }

  // 商品图片
  Widget _goodsImage(url){
    return Image.network(
      url,
      width: ScreenUtil().setWidth(740),
    );
  }

  //商品名称
  Widget _goodsName(name){
    return Container(
      width: ScreenUtil().setWidth(740),
      padding: EdgeInsets.only(left: 15.0),
      child: Text(
        name,
        style:TextStyle(
          fontSize: ScreenUtil().setSp(30)
        )
      ),
    );
  }

  //商品编号
  Widget _gooddsNum(num){
  return Container(
    width: ScreenUtil().setWidth(740),
    padding: EdgeInsets.only(left: 15.0),
    margin: EdgeInsets.only(top: 8.0),
    child: Text(
      '编号${num}',
      style: TextStyle(
        color: Colors.black12
      ),
    ),
    );
  }

  //商品价格
  Widget _goodsPrice(presentPrice,oriPrice){
    return Container(
      width: ScreenUtil().setWidth(740),
      padding: EdgeInsets.only(left: 15.0),
      margin: EdgeInsets.only(top: 8.0),
      child: Row(
        children: <Widget>[
          Text(
            '￥${presentPrice}',
            style: TextStyle(
              color: Colors.red,
              fontSize: ScreenUtil().setSp(30)
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 16.0),
            child: Row(
              children: <Widget>[
                Text(
                  '市场价：',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(24)
                  ),
                ),
                Text(
                  '￥${oriPrice}',
                  style: TextStyle(
                    color: Colors.black12,
                    fontSize: ScreenUtil().setSp(28),
                    decoration: TextDecoration.lineThrough
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
